<?php

namespace app\admin\controller;

use think\facade\Cache;

/**
 * Class Index
 * @package app\admin\controller
 */
class Caches extends CommonController
{
    public function index()
    {
        if ($this->isAjax())
        {
            $request = $this->request;
            $type = $request['type'];
            switch ($type) {
                case 0:
                    // 清除缓存
                case 1:
                    rmdirs(rootPath() . 'runtime/temp');    // 插件模板缓存
                    rmdirs(rootPath() . 'runtime/admin/temp');  // 后台模板缓存
                    break;
                // 数据表缓存清除
                case 2:
                    Cache::clear();
                    break;
                default:
                    break;
            }
            return $this->success();
        }
        return view();
    }
}
